import React, { Component } from 'react'

export default class Child extends Component {
  componentDidMount() {
    console.log('componentDidMount')
  }

  render() {
    console.log('render', this.props.name)
    return (
      <li className={this.props.active ? 'active' : ''}>{this.props.name}</li>
    )
  }

  shouldComponentUpdate(nextProps, nextState) {
    if (JSON.stringify(nextProps) !== JSON.stringify(this.props)) {
      console.log('shouldComponentUpdate')
      return true
    }
    return false // 阻止更新
  }

  //WARNING! To be deprecated in React v17. Use componentDidUpdate instead.
  componentWillUpdate(nextProps, nextState) {
    console.log('componentWillUpdate')
  }

  componentDidUpdate(prevProps, prevState) {
    console.log('componentDidUpdate')
  }
}
